package com.hsh.member.controller;

import com.hsh.member.base.Result;
import com.hsh.member.entity.Staff;
import com.hsh.member.req.PasswordREQ;
import com.hsh.member.req.StaffREQ;
import com.hsh.member.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author
 * @date2022/12/2 16:22
 */
@RestController
@RequestMapping("/user")
public class AuthController {

  @Autowired
  private IStaffService staffService;

  /*
   校验原密码是否正确  localhost:7777/user/pwd
   */
  @PostMapping("/pwd")
  public Result checkPwd(@RequestBody PasswordREQ req){
    return  staffService.checkPassword(req);
  }

  /*
   提交修改密码 localhost:7777/user/pwd
   */
  @PutMapping("/pwd")
  public Result  updatePwd(@RequestBody PasswordREQ req){
    return  staffService.updatePassWord(req);
  }

  @PostMapping("/login")
  public Result login(@RequestBody() Staff staff){
     return staffService.login(staff.getUsername(), staff.getPassword());
  }

  /*
    通过token 获取用户信息
     /user/info?token=xxx
    */
  @GetMapping("/info")
  public Result getUserInfo(@RequestParam String token){
    return staffService.getUserInfo(token);
  }


  @PostMapping("/logout")
  public  Result logout(){
    return  Result.ok();
  }
}
